package com.fbs.wowo.manage.mapper;

import com.fbs.wowo.manage.entity.User;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface UserMapper {
    @Delete({
        "delete from user",
        "where id = #{id,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String id);

    @InsertProvider(type=UserSqlProvider.class, method="insertSelective")
    int insertSelective(User record);

    @Select({
        "select",
        "id, user_id, rc_token, name, password, tel, sex, age, invitation_code, photo, ",
        "brief, last_login_time, ip, create_time, update_time, token, tel_salt, salt, ",
        "crew_num, status, unlock_time,credit_points,user_type",
        "from user",
        "where id = #{id,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="user_id", property="userId", jdbcType=JdbcType.VARCHAR),
        @Result(column="rc_token", property="rcToken", jdbcType=JdbcType.VARCHAR),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
        @Result(column="tel", property="tel", jdbcType=JdbcType.VARCHAR),
        @Result(column="sex", property="sex", jdbcType=JdbcType.TINYINT),
        @Result(column="age", property="age", jdbcType=JdbcType.TINYINT),
        @Result(column="invitation_code", property="invitationCode", jdbcType=JdbcType.VARCHAR),
        @Result(column="photo", property="photo", jdbcType=JdbcType.VARCHAR),
        @Result(column="brief", property="brief", jdbcType=JdbcType.VARCHAR),
        @Result(column="last_login_time", property="lastLoginTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="ip", property="ip", jdbcType=JdbcType.VARCHAR),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="token", property="token", jdbcType=JdbcType.VARCHAR),
        @Result(column="tel_salt", property="telSalt", jdbcType=JdbcType.VARCHAR),
        @Result(column="salt", property="salt", jdbcType=JdbcType.VARCHAR),
        @Result(column="crew_num", property="crewNum", jdbcType=JdbcType.INTEGER),
        @Result(column="status", property="status", jdbcType=JdbcType.TINYINT),
        @Result(column="unlock_time", property="unlockTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="credit_points", property="creditPoints", jdbcType=JdbcType.INTEGER),
        @Result(column="user_type", property="userType", jdbcType=JdbcType.TINYINT)
    })
    User selectByPrimaryKey(String id);

    @UpdateProvider(type=UserSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(User record);

    /**
     * @return user 用户
     */
    @Select({
            "select",
            "count(user_id)",
            "from user"
    })
    Integer getCount();

    /**
     * 按自己的邀请码找
     * @param invitationCode 邀请码
     * @return
     */
    @Select({
            "select",
            "id, user_id, rc_token, name, password, tel, sex, age, invitation_code, photo, ",
            "brief, last_login_time, ip, create_time, update_time, token, tel_salt, salt, ",
            "crew_num, status, unlock_time,credit_points,user_type",
            "from user",
            "where invitation_code = #{invitationCode,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.VARCHAR, id=true),
            @Result(column="user_id", property="userId", jdbcType=JdbcType.VARCHAR),
            @Result(column="rc_token", property="rcToken", jdbcType=JdbcType.VARCHAR),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
            @Result(column="tel", property="tel", jdbcType=JdbcType.VARCHAR),
            @Result(column="sex", property="sex", jdbcType=JdbcType.TINYINT),
            @Result(column="age", property="age", jdbcType=JdbcType.TINYINT),
            @Result(column="invitation_code", property="invitationCode", jdbcType=JdbcType.VARCHAR),
            @Result(column="photo", property="photo", jdbcType=JdbcType.VARCHAR),
            @Result(column="brief", property="brief", jdbcType=JdbcType.VARCHAR),
            @Result(column="last_login_time", property="lastLoginTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="ip", property="ip", jdbcType=JdbcType.VARCHAR),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="token", property="token", jdbcType=JdbcType.VARCHAR),
            @Result(column="tel_salt", property="telSalt", jdbcType=JdbcType.VARCHAR),
            @Result(column="salt", property="salt", jdbcType=JdbcType.VARCHAR),
            @Result(column="crew_num", property="crewNum", jdbcType=JdbcType.INTEGER),
            @Result(column="status", property="status", jdbcType=JdbcType.TINYINT),
            @Result(column="unlock_time", property="unlockTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="credit_points", property="creditPoints", jdbcType=JdbcType.INTEGER),
            @Result(column="user_type", property="userType", jdbcType=JdbcType.TINYINT)

    })
    User findByInvitationCode(String invitationCode);

    /**
     * 按电话号码查找
     * @param tel 电话号码
     * @return user 用户
     */
    @Select({
            "select",
            "id, user_id, rc_token, name, password, tel, sex, age, invitation_code, photo, ",
            "brief, last_login_time, ip, create_time, update_time, token, tel_salt, salt, ",
            "crew_num, status, unlock_time,credit_points,user_type",
            "from user",
            "where tel = #{tel,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.VARCHAR, id=true),
            @Result(column="user_id", property="userId", jdbcType=JdbcType.VARCHAR),
            @Result(column="rc_token", property="rcToken", jdbcType=JdbcType.VARCHAR),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
            @Result(column="tel", property="tel", jdbcType=JdbcType.VARCHAR),
            @Result(column="sex", property="sex", jdbcType=JdbcType.TINYINT),
            @Result(column="age", property="age", jdbcType=JdbcType.TINYINT),
            @Result(column="invitation_code", property="invitationCode", jdbcType=JdbcType.VARCHAR),
            @Result(column="photo", property="photo", jdbcType=JdbcType.VARCHAR),
            @Result(column="brief", property="brief", jdbcType=JdbcType.VARCHAR),
            @Result(column="last_login_time", property="lastLoginTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="ip", property="ip", jdbcType=JdbcType.VARCHAR),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="token", property="token", jdbcType=JdbcType.VARCHAR),
            @Result(column="tel_salt", property="telSalt", jdbcType=JdbcType.VARCHAR),
            @Result(column="salt", property="salt", jdbcType=JdbcType.VARCHAR),
            @Result(column="crew_num", property="crewNum", jdbcType=JdbcType.INTEGER),
            @Result(column="status", property="status", jdbcType=JdbcType.TINYINT),
            @Result(column="unlock_time", property="unlockTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="credit_points", property="creditPoints", jdbcType=JdbcType.INTEGER),
            @Result(column="user_type", property="userType", jdbcType=JdbcType.TINYINT)
    })
    User findByTel(String tel);

    /**
     * @param tel 用户Id
     * @return user 用户
     */
    @Select({
            "select",
            "id, user_id, rc_token, name, password, tel, sex, age, invitation_code, photo, ",
            "brief, last_login_time, ip, create_time, update_time, token, tel_salt, salt, ",
            "crew_num, status, unlock_time,credit_points,user_type",
            "from user",
            "where tel = #{tel,jdbcType=VARCHAR} and status = 1"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.VARCHAR, id=true),
            @Result(column="user_id", property="userId", jdbcType=JdbcType.VARCHAR),
            @Result(column="rc_token", property="rcToken", jdbcType=JdbcType.VARCHAR),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
            @Result(column="tel", property="tel", jdbcType=JdbcType.VARCHAR),
            @Result(column="sex", property="sex", jdbcType=JdbcType.TINYINT),
            @Result(column="age", property="age", jdbcType=JdbcType.TINYINT),
            @Result(column="invitation_code", property="invitationCode", jdbcType=JdbcType.VARCHAR),
            @Result(column="photo", property="photo", jdbcType=JdbcType.VARCHAR),
            @Result(column="brief", property="brief", jdbcType=JdbcType.VARCHAR),
            @Result(column="last_login_time", property="lastLoginTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="ip", property="ip", jdbcType=JdbcType.VARCHAR),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="token", property="token", jdbcType=JdbcType.VARCHAR),
            @Result(column="tel_salt", property="telSalt", jdbcType=JdbcType.VARCHAR),
            @Result(column="salt", property="salt", jdbcType=JdbcType.VARCHAR),
            @Result(column="crew_num", property="crewNum", jdbcType=JdbcType.INTEGER),
            @Result(column="status", property="status", jdbcType=JdbcType.TINYINT),
            @Result(column="unlock_time", property="unlockTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="credit_points", property="creditPoints", jdbcType=JdbcType.INTEGER),
            @Result(column="user_type", property="userType", jdbcType=JdbcType.TINYINT)
    })
    User findByTelAndStatus(String tel);

    /**
     * 按userId查找
     * @param userId 用户Id
     * @return user 用户
     */
    @Select({
            "select",
            "id, user_id, rc_token, name, password, tel, sex, age, invitation_code, photo, ",
            "brief, last_login_time, ip, create_time, update_time, token, tel_salt, salt, ",
            "crew_num, status, unlock_time,credit_points,user_type",
            "from user",
            "where user_id = #{userId,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.VARCHAR, id=true),
            @Result(column="user_id", property="userId", jdbcType=JdbcType.VARCHAR),
            @Result(column="rc_token", property="rcToken", jdbcType=JdbcType.VARCHAR),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
            @Result(column="tel", property="tel", jdbcType=JdbcType.VARCHAR),
            @Result(column="sex", property="sex", jdbcType=JdbcType.TINYINT),
            @Result(column="age", property="age", jdbcType=JdbcType.TINYINT),
            @Result(column="invitation_code", property="invitationCode", jdbcType=JdbcType.VARCHAR),
            @Result(column="photo", property="photo", jdbcType=JdbcType.VARCHAR),
            @Result(column="brief", property="brief", jdbcType=JdbcType.VARCHAR),
            @Result(column="last_login_time", property="lastLoginTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="ip", property="ip", jdbcType=JdbcType.VARCHAR),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="token", property="token", jdbcType=JdbcType.VARCHAR),
            @Result(column="tel_salt", property="telSalt", jdbcType=JdbcType.VARCHAR),
            @Result(column="salt", property="salt", jdbcType=JdbcType.VARCHAR),
            @Result(column="crew_num", property="crewNum", jdbcType=JdbcType.INTEGER),
            @Result(column="status", property="status", jdbcType=JdbcType.TINYINT),
            @Result(column="unlock_time", property="unlockTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="credit_points", property="creditPoints", jdbcType=JdbcType.INTEGER),
            @Result(column="user_type", property="userType", jdbcType=JdbcType.TINYINT)
    })
    User findByUserId(String userId);

    /**
     * 按用户id 模糊查询用户
     * @param userId id
     */
    @Select({
            "select",
            "id, user_id, rc_token, name, password, tel, sex, age, invitation_code, photo, ",
            "brief, last_login_time, ip, create_time, update_time, token, tel_salt, salt, ",
            "crew_num, status, unlock_time,credit_points,user_type",
            "from user",
            "where user_id like \"%\"#{userId,jdbcType=VARCHAR}\"%\""
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.VARCHAR, id=true),
            @Result(column="user_id", property="userId", jdbcType=JdbcType.VARCHAR),
            @Result(column="rc_token", property="rcToken", jdbcType=JdbcType.VARCHAR),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
            @Result(column="tel", property="tel", jdbcType=JdbcType.VARCHAR),
            @Result(column="sex", property="sex", jdbcType=JdbcType.TINYINT),
            @Result(column="age", property="age", jdbcType=JdbcType.TINYINT),
            @Result(column="invitation_code", property="invitationCode", jdbcType=JdbcType.VARCHAR),
            @Result(column="photo", property="photo", jdbcType=JdbcType.VARCHAR),
            @Result(column="brief", property="brief", jdbcType=JdbcType.VARCHAR),
            @Result(column="last_login_time", property="lastLoginTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="ip", property="ip", jdbcType=JdbcType.VARCHAR),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="token", property="token", jdbcType=JdbcType.VARCHAR),
            @Result(column="tel_salt", property="telSalt", jdbcType=JdbcType.VARCHAR),
            @Result(column="salt", property="salt", jdbcType=JdbcType.VARCHAR),
            @Result(column="crew_num", property="crewNum", jdbcType=JdbcType.INTEGER),
            @Result(column="status", property="status", jdbcType=JdbcType.TINYINT),
            @Result(column="unlock_time", property="unlockTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="credit_points", property="creditPoints", jdbcType=JdbcType.INTEGER),
            @Result(column="user_type", property="userType", jdbcType=JdbcType.TINYINT)
    })
    List<User> searchById(String userId);

    /**
     * 按用户电话号码模糊查询
     * @param tel 电话号码
     */
    @Select({
            "select",
            "id, user_id, rc_token, name, password, tel, sex, age, invitation_code, photo, ",
            "brief, last_login_time, ip, create_time, update_time, token, tel_salt, salt, ",
            "crew_num, status, unlock_time,credit_points,user_type",
            "from user",
            "where tel like \"%\"#{tel,jdbcType=VARCHAR}\"%\""
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.VARCHAR, id=true),
            @Result(column="user_id", property="userId", jdbcType=JdbcType.VARCHAR),
            @Result(column="rc_token", property="rcToken", jdbcType=JdbcType.VARCHAR),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
            @Result(column="tel", property="tel", jdbcType=JdbcType.VARCHAR),
            @Result(column="sex", property="sex", jdbcType=JdbcType.TINYINT),
            @Result(column="age", property="age", jdbcType=JdbcType.TINYINT),
            @Result(column="invitation_code", property="invitationCode", jdbcType=JdbcType.VARCHAR),
            @Result(column="photo", property="photo", jdbcType=JdbcType.VARCHAR),
            @Result(column="brief", property="brief", jdbcType=JdbcType.VARCHAR),
            @Result(column="last_login_time", property="lastLoginTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="ip", property="ip", jdbcType=JdbcType.VARCHAR),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="token", property="token", jdbcType=JdbcType.VARCHAR),
            @Result(column="tel_salt", property="telSalt", jdbcType=JdbcType.VARCHAR),
            @Result(column="salt", property="salt", jdbcType=JdbcType.VARCHAR),
            @Result(column="crew_num", property="crewNum", jdbcType=JdbcType.INTEGER),
            @Result(column="status", property="status", jdbcType=JdbcType.TINYINT),
            @Result(column="unlock_time", property="unlockTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="credit_points", property="creditPoints", jdbcType=JdbcType.INTEGER),
            @Result(column="user_type", property="userType", jdbcType=JdbcType.TINYINT)
    })
    List<User> searchByTel(String tel);

    /**
     * 按用户名模糊查询
     * @param name 用户名
     */
    @Select({
            "select",
            "id, user_id, rc_token, name, password, tel, sex, age, invitation_code, photo, ",
            "brief, last_login_time, ip, create_time, update_time, token, tel_salt, salt, ",
            "crew_num, status, unlock_time,credit_points,user_type",
            "from user",
            "where name like \"%\"#{name,jdbcType=VARCHAR}\"%\""
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.VARCHAR, id=true),
            @Result(column="user_id", property="userId", jdbcType=JdbcType.VARCHAR),
            @Result(column="rc_token", property="rcToken", jdbcType=JdbcType.VARCHAR),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
            @Result(column="tel", property="tel", jdbcType=JdbcType.VARCHAR),
            @Result(column="sex", property="sex", jdbcType=JdbcType.TINYINT),
            @Result(column="age", property="age", jdbcType=JdbcType.TINYINT),
            @Result(column="invitation_code", property="invitationCode", jdbcType=JdbcType.VARCHAR),
            @Result(column="photo", property="photo", jdbcType=JdbcType.VARCHAR),
            @Result(column="brief", property="brief", jdbcType=JdbcType.VARCHAR),
            @Result(column="last_login_time", property="lastLoginTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="ip", property="ip", jdbcType=JdbcType.VARCHAR),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="token", property="token", jdbcType=JdbcType.VARCHAR),
            @Result(column="tel_salt", property="telSalt", jdbcType=JdbcType.VARCHAR),
            @Result(column="salt", property="salt", jdbcType=JdbcType.VARCHAR),
            @Result(column="crew_num", property="crewNum", jdbcType=JdbcType.INTEGER),
            @Result(column="status", property="status", jdbcType=JdbcType.TINYINT),
            @Result(column="unlock_time", property="unlockTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="credit_points", property="creditPoints", jdbcType=JdbcType.INTEGER),
            @Result(column="user_type", property="userType", jdbcType=JdbcType.TINYINT)
    })
    List<User> searchByName(String name);
}